import { createStore, applyMiddleware } from "redux";

import thunk from 'redux-thunk'

import reducers from "./reducers/main.js";
import createHistory from 'history/createHashHistory'
// console.log('1:' + createHistory, '2:' + createHistory2)
import { routerMiddleware } from 'react-router-redux'

const history = createHistory()
history.replace('/home')
const historyMiddleware = routerMiddleware(history);

// console.log("main", reducers);
const store = createStore(reducers, applyMiddleware(thunk, historyMiddleware));

if (module.hot) {
  module.hot.accept("./reducers/main", () => {
    const nextRootReducer = require("./reducers/main.js").default;
    store.replaceReducer(nextRootReducer);
  });
}

module.exports = {
  store,
  history
}
